package cn.xo68.boot.auth.server.mapper;

import cn.xo68.boot.auth.server.domain.OauthUserRole;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * OauthUserRoleDto mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月28日 11:04:12
 *
 */
public interface OauthUserRoleMapper {


	@Select("SELECT role_id FROM oauth_user_role WHERE user_id = #{UserId}")
    @Results(value = {
        @Result(column = "role_id", property = "roleId")
    })
    List<String> getUserRoles(@Param("UserId") String UserId);
	
	@Select("SELECT * FROM oauth_user_role WHERE serial_id = #{serialId}")
    @Results(value = { 
    @Result(id = true, column = "serial_id", property = "serialId"),
        @Result(column = "user_id", property = "userId"),
        @Result(column = "role_id", property = "roleId"),
        @Result(column = "operator_name", property = "operatorName"),
        @Result(column = "operator_id", property = "operatorId"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    OauthUserRole find(@Param("serialId") String serialId);
	
	@Select("SELECT * FROM oauth_user_role")
    @Results(value = { 
    @Result(id = true, column = "serial_id", property = "serialId"),
        @Result(column = "user_id", property = "userId"),
        @Result(column = "role_id", property = "roleId"),
            @Result(column = "operator_name", property = "operatorName"),
        @Result(column = "operator_id", property = "operatorId"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    List<OauthUserRole> list();
	
	@Insert("insert into oauth_user_role (serial_id ,user_id ,role_id ,operator_name ,operator_id ,create_time ,update_time ) values (#{serialId} , #{userId} , #{roleId} , #{operatorName} , #{operatorId} , #{createTime} , #{updateTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "serialId")
    void insert(OauthUserRole oauthUserRole);
	
	@Update("update oauth_user_role set  user_id=#{userId}, role_id=#{roleId}, operator_name=#{operatorName}, operator_id=#{operatorId}, update_time=#{updateTime} where serial_id = #{serialId}")
    void update(OauthUserRole oauthUserRole);

	@Delete("delete FROM oauth_user_role WHERE user_id = #{userId}")
	void delete(@Param("userId") String userId);
}